<?php
  require_once('tpl/header.php');
?>

   <?php 
	//连接数据库，接收表单数据，写sql修改用户信息
	/*mysql_connect("localhost","root","");
	mysql_select_db("neuvideo");
	mysql_query("set names utf8");*/
	//require("../system/dbConn.php");
		connect();

	$uid=$_POST["uid"];
	$username=$_POST["username"];
	$gender=$_POST["gender"];
	$birthdate=$_POST["birthdate"];
	$email=$_POST["email"];
	

	//文件上传
	// var_dump($_FILES);

	//文件上传出错判定
	if ($_FILES["pic"]["error"]>0) {//1,3,4
		switch ($_FILES["pic"]["error"]) {
			case '1':
				echo "文件尺寸超出了最大配置值";
				break;

			case '3':
				echo "文件上传不完整";
				break;

			case '4':
				echo "没有文件上传";
				$sql="update users set uname='$username',gender=$gender,birthdate='$birthdate',email='$email' where uid=$uid";
				break;
			
			default:
				echo "未知错误";
				break;
		}
		
	}else{


	//判断图片文件类型
	$allowtype=array("jpg","JPG","jpeg","JPEG","png","PNG","gif","GIF","bmp","BMP","svg","SVG");
	//重命名
	$arr=explode(".", $_FILES["pic"]["name"]);

	$filepath="../images/";
	$suffix=$arr[count($arr)-1];
	if (!in_array($suffix, $allowtype)) {
		echo"您上传的文件不是图片类选";
		exit;
		// die("您上传的文件不是图片类选");
	}

	$newname=date("YmdHis").rand(100,999).".".$suffix;

//拷贝文件
	if(move_uploaded_file($_FILES["pic"]["tmp_name"], $filepath.$newname))
	{
		echo "头像上传成功"."<br>";

	}else{
		echo "头像上传失败"."<br>";
	}



//sql语句
	$sql="update users set uname='$username',gender=$gender,birthdate='$birthdate',email='$email',pic='$newname' where uid=$uid";
}//判定error的else结束

	$result=mysql_query($sql);
	if ($result==1) {
		echo "用户信息修改成功，3秒后跳转到列表页";
		header("refresh:3;url='userList.php");
	}else{
		echo "用户信息修改失败";
	}

//编写sql语句，添加到数据库中的users数据表中
	/*$sql="insert into users values(null,'$username',md5('$password'),$gender,'$birthdate','$newname','$email')";
	$result=mysql_query($sql);  //执行sql语句
	if($result==1){
		echo "注册成功，您的信息已写入数据库";
	}else{
		echo "注册失败!";
	}*/
	 ?>


<?php
  require_once('tpl/footer.php');
?>